package com.foryou.system.modules.wx.controller;

import com.foryou.system.common.bootstrap.PageUtils;
import com.foryou.system.common.bootstrap.Query;
import com.foryou.system.common.utils.R;
import com.foryou.system.modules.wx.entity.SysMsgEntity;
import com.foryou.system.modules.wx.service.SysMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by Lee.
 */
@RestController
@RequestMapping("/wx/sys/msg")
public class SysMsgController {

    @Autowired
    private SysMsgService sysMsgService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        int total = sysMsgService.queryTotal(query);
        List<SysMsgEntity> sysLogList = sysMsgService.queryList(query);

        PageUtils pageUtil = new PageUtils(sysLogList, total);
        return pageUtil;
    }

    @RequestMapping("/update")
    public R update(@RequestBody Map<String, Object> params) {
        if (sysMsgService.update(params) > 0) {
            return R.ok();
        }
        return R.error();
    }

    @GetMapping("/selectList")
    public List<SysMsgEntity> selectList() {
        return sysMsgService.selectList();
    }

    @RequestMapping("/add")
    public R add(@RequestBody Map<String, Object> params) {
        if (sysMsgService.add(params) > 0) {
            return R.ok();
        }
        return R.error();
    }

    @GetMapping("/getInfo/{id}")
    public R getInfo(@PathVariable("id") Long id) {
        return R.ok().put("data",sysMsgService.getInfo(id));
    }

    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        sysMsgService.deleteBatch(ids);
        return R.ok();
    }

}
